Unit BModelCodePartsUnit;

{$mode objfpc}{$H+}

Interface

ResourceString

  // Save
  CODE_SAVE_PEAS_PLURAL =
    'Function B%0:sClass.Save%3:s(Const aQuery: BQueryClass): Boolean;\' +
    'Var\' +
    '  i: Integer;\' +
    '  aSQL: BSQLClass;\' +
    '  aList: B%2:sList;\' +
    '  a%2:sManager: B%2:sManagerClass;\' +
    'Begin\' +
    '  aSQL := BSQLClass.Build;\' +
    '  a%2:sManager := B%2:sManagerClass.Build;\' +
    '  aList := b%3:s.LockList;\' +
    '  Try\' +
    '    aSQL.Builder.Delete(SQL_NAME + ''_'' + SQL_%4:s).Where(SQL_NAME_MATCH);\' +
    '    aSQL.AddParam(SQL_NAME, %1:sID);\' +
    '    Result := aQuery.Post(aSQL);\' +
    ' \' +
    '    aSQL.Clear;\' +
    '    aSQL.Builder.Insert(SQL_NAME + ''_'' + SQL_%4:s).AddParam(SQL_NAME).\' +
    '      AddParam(SQL_%4:s);\' +
    '    aSQL.AddParam(SQL_NAME, %1:sID);\' +
    '    For i := 0 To aList.Count - 1 Do\' +
    '      Begin\' +
    '        aSQL.AddParam(SQL_%4:s, aList[i].ID);\' +
    '        Result := Result And aQuery.Post(aSQL);\' +
    '      End;\' +
    '  Finally\' +
    '    b%3:s.UnlockList;\' +
    '    a%2:sManager.Burn;\' +
    '    aSQL.Burn;\' +
    '  End;\' +
    'End;\' +
    ' \';

  CODE_SAVE_HOLDERS_PLURAL =
    'Function B%0:sClass.Save%3:s(Const aQuery: BQueryClass): Boolean;\' +
    'Var\' +
    '  i: Integer;\' +
    '  aSQL: BSQLClass;\' +
    '  aList: B%2:sList;\' +
    'Begin\' +
    '  aSQL := BSQLClass.Build;\' +
    '  aList := b%3:s.LockList;\' +
    '  Try\' +
    '    aSQL.Builder.Delete(SQL_NAME + ''_'' + SQL_%4:s).Where(SQL_NAME_MATCH);\' +
    '    aSQL.AddParam(SQL_NAME, ID);\' +
    '    Result := aQuery.Post(aSQL);\' +
    ' \' +
    '    For i := 0 To aList.Count - 1 Do\' +
    '      Result := Result And aList[i].Save(ID, SQL_NAME + ''_'' + SQL_%4:s, ' +
           'SQL_NAME, aQuery);\' +
    '  Finally\' +
    '    b%3:s.UnlockList;\' +
    '    aSQL.Burn;\' +
    '  End;\' +
    'End;\' +
    ' \';

  CODE_SAVE_PLAIN_PLURAL =
    'Function B%0:sClass.Save%1:s(Const aQuery: BQueryClass): Boolean;\' +
    'Var\' +
    '  i: Integer;\' +
    '  aSQL: BSQLClass;\' +
    'Begin\' +
    '  aSQL := BSQLClass.Build;\' +
    '  Try\' +
    '    aSQL.Builder.Delete(SQL_NAME + ''_'' + SQL_%2:s).\' +
    '      Where(SQL_NAME_MATCH);\' +
    '    Result := aQuery.Post(aSQL);\' +
    '    aSQL.Clear;\' +
    '    aSQL.Builder.Insert(SQL_NAME + ''_'' + SQL_%2:s).\' +
    '      AddParam(SQL_NAME).AddParam(SQL_%2:s);\' +
    '    aSQL.AddParam(SQL_NAME, ID);\' +
    '    With b%1:s.LockList Do\' +
    '      For i := 0 To Count - 1 Do\' +
    '        Begin\' +
    '          aSQL.AddParam(SQL_%2:s, Items[i]);\' +
    '          Result := Result And aQuery.Post(aSQL);\' +
    '        End;\' +
    '    b%1:s.UnlockList;\' +
    '  Finally\' +
    '    aSQL.Burn;\' +
    '  End;\' +
    'End;\'+
    ' \';

  CODE_SAVE_HOLDER =
    '    aSQL.Builder.Insert(aOwnerTable).AddParam(aOwnerName).' +
           'AddParam(SQL_HOLDING_NAME)%1:s;\' +
    '    aSQL.AddParam(aOwnerName, aOwnerID);\' +
    '    aSQL.AddParam(SQL_HOLDING_NAME, %0:s.ID);\' +
    ' \';

  // Load Plural
  CODE_LOAD_HOLDERS_PLURAL =
    'Procedure B%0:sClass.Load%1:s(Const a%1:s: %2:s);\' +
    'Var\' +
    '  i: Integer;\' +
    'Begin\' +
    '  b%1:s.Purge;\' +
    '  For i := 0 To a%1:s.Count - 1 Do\' +
    '    b%1:s.Add(a%1:s[i].Clone);\' +
    'End;\' +
    ' \';
  CODE_LOAD_PEAS_PLURAL =
    '';
  CODE_LOAD_PLAIN_PLURAL =
    'Procedure B%0:sClass.Load%1:s(Const a%1:s: %2:s);\' +
    'Begin\' +
    '  b%1:s.Load(a%1:s);\' +
    'End;\' +
    ' \';

  CODE_ORIGINAL_LOAD_PLAIN_PLURAL =
    '  b%0:s.Load(aObject.%0:s.LockList);\' +
    '  aObject.%0:s.UnlockList;\' +
    ' \';
  CODE_ORIGINAL_LOAD_HOLDERS_PLURAL =
    '  b%0:s.Purge;\' +
    '  With aObject.%0:s.LockList Do \' +
    '    For i := 0 To Count - 1 Do \' +
    '      b%0:s.Add(Items[i].Clone);\' +
    '  aObject.%0:s.UnlockList;\' +
    ' \';

  // Holder
  CODE_CLONE_PLAIN_PLURAL =
    '  Result.%0:s.Load(%0:s.LockList);\' +
    '  %0:s.UnlockList;\' +
    ' \';
  CODE_CLONE_HOLDERS_PLURAL =
    '  With %0:s.LockList Do\' +
    '    Try\' +
    '      For i := 0 To Count - 1 Do\' +
    '        Result.%0:s.Add(Items[i].Clone);\' +
    '  Finally\' +
    '    %0:s.UnlockList;\' +
    '  End;\' +
    ' \';



  // Manager Load
  // TODO: compose PEAS and HOLDERS code masks
  CODE_MANAGER_PEAS_LOAD =

    'Var\' +
    '  aSQL: BSQLClass;\' +
    '  a%0:s: B%0:sClass;\' +
    '  a%4:s: B%4:sClass;\' +
    '  a%5:sManager: B%5:sManagerClass;\' +
    'Begin\' +
    '  aSQL := BSQLClass.Build;\' +
    '  aSQL.Builder.Select(SQL_NAME + ''_'' + SQL_%3:s).All;\' +
    '  a%5:sManager := B%5:sManagerClass.Build;\' +
    '  Try;\' +
    '    aQuery.Get(aSQL);\' +
    '    While Not(aQuery.EOF) Do\' +
    '      Begin\' +
    '        a%0:s := GetObject(aQuery.ByInteger(SQL_NAME));\' +
    '        a%4:s := a%5:sManager.GetObject(aQuery.ByInteger(SQL_%3:s));\' +
    '        If Not((a%0:s = nil) Or (a%4:s = nil)) Then\' +
    '          a%0:s.b%2:s.Add(a%4:s);\' +
    '        aQuery.Next;\' +
    '      End;\' +
    '  Finally\' +
    '    a%5:sManager.Burn;\' +
    '    aSQL.Burn;\' +
    '  End;\' +
    'End;\' +
    ' \';

  CODE_MANAGER_HOLDERS_LOAD =
    'Var\' +
    '  i: Integer;\' +
    '  aList: B%8:sOwnersList;\' +
    '  aSQL: BSQLClass;\' +
    '  a%0:s: B%0:sClass;\' +
    '  a%6:s: B%6:sClass;\' +
    '  a%4:s: B%4:sClass;\' +
    '  a%5:sManager: B%5:sManagerClass;\' +
    'Begin\' +
    '  aList := B%8:sOwnersList.Build;\' +
    '  Try\' +
    '    With Committed.LockList Do\' +
    '      For i := 0 To Count - 1 Do\' +
    '        aList.Add(B%8:sOwnerClass.Build(Items[i].ID, Items[i].%2:s));\' +
    '      Load%8:s(aList, SQL_NAME + ''_'' + SQL_%3:s, SQL_NAME, aQuery);\' +
    '  Finally\' +
    '    Committed.UnlockList;\' +
    '    For i := 0 To aList.Count - 1 Do\' +
    '      aList[i].Burn;\' +
    '    aList.Burn;\' +
    '  End;\' +
    'End;\' +
    ' \';

  CODE_MANAGER_PLAIN_LOAD =
    'Var\' +
    '  aSQL: BSQLClass;\' +
    '  a%0:s: B%0:sClass;\' +
    'Begin\' +
    '  aSQL := BSQLClass.Build;\' +
    '  aSQL.Builder.Select(SQL_NAME + ''_'' + SQL_%3:s).All;\' +
    '  Try;\' +
    '    aQuery.Get(aSQL);\' +
    '    While Not(aQuery.EOF) Do\' +
    '      Begin\' +
    '        a%0:s := GetObject(aQuery.ByInteger(SQL_NAME));\' +
    '        If Not(a%0:s = nil) Then\' +
    '          a%0:s.%2:s.Add(aQuery.%4:s(SQL_%3:s));\' +
    '        aQuery.Next;\' +
    '      End;\' +
    '  Finally\' +
    '    aSQL.Burn;\' +
    '  End;\' +
    'End;\' +
    ' \';

  CODE_HOLDER_LOAD_PLAIN =

    ' \';



Implementation

End.

